<?php

namespace App\Store\Validate\Wxapp\WxappGift;

use App\Common\Validate\BaseValidate;

/**
 * 权限组验证器
 */
class WxappGiftStock extends BaseValidate
{

    //验证规则
    protected $rule = [];
    //自定义验证信息
    protected $message = [];
    

    public function __construct($doaction = 'add')
    {
        if ($doaction == 'add') {
            $this->rule = [
                'gift_name'=>'required',
                'gift_category_id' => 'required|integer|gt:0',
                'price' => 'required|integer|gt:0',
                'total_count' => 'required|integer|gt:0',
                'need_points' => 'required|integer|gt:0',
                'piecelimit' => 'required|integer|gte:0',
                'valid_type' => 'required|in:1,2,3,4,5,6,7',
                'gift_img'=>'required',
            ];
            $this->message = [
                'gift_name.required' => '礼品名称不能为空',
                'gift_category_id.required' => '礼品类别未选择',
                'gift_category_id.integer' => '礼品类别参数错误',
                'gift_category_id.gt' => '礼品类别参数错误',
                'price.required' => '价值不能为空',
                'price.integer' => '价值参数错误',
                'price.gt' => '价值参数错误',
                'total_count.required' => '数量不能为空',
                'total_count.integer' => '数量需为大于0整数',
                'total_count.gt' => '数量需为大于0整数',
                'need_points.required' => '所需积分不能为空',
                'need_points.integer' => '所需积分需为大于0整数',
                'need_points.gt' => '所需积分需为大于0整数',
                'piecelimit.required' => '兑换次数限制不能为空',
                'piecelimit.integer' => '兑换次数限制参数错误',
                'piecelimit.gt' => '兑换次数限制参数错误',
                'valid_type.required' => '有效期类型不能为空',
                'valid_type.in' => '有效期类型参数错误',
                'gift_img.required' => '礼品图片不能为空',
            ];
        } elseif ($doaction == 'edit') {
            $this->rule = [
                'id' => 'required|integer|gt:0',
                'gift_name'=>'required',
                'gift_category_id' => 'required|integer|gt:0',
                'price' => 'required|integer|gt:0',
                'total_count' => 'required|integer|gt:0',
                // 'need_points' => 'required|integer|gt:0',
                'piecelimit' => 'required|integer|gte:0',
                'valid_type' => 'required|in:1,2,3,4,5,6,7',
                'gift_img'=>'required',
            ];
            $this->message = [
                'id.required' => '参数错误',
                'id.integer' => '参数错误',
                'id.gt' => '参数错误',
                'gift_name.required' => '礼品名称不能为空',
                'gift_category_id.required' => '礼品类别未选择',
                'gift_category_id.integer' => '礼品类别参数错误',
                'gift_category_id.gt' => '礼品类别参数错误',
                'price.required' => '价值不能为空',
                'price.integer' => '价值参数错误',
                'price.gt' => '价值参数错误',
                'total_count.required' => '数量不能为空',
                'total_count.integer' => '数量需为大于0整数',
                'total_count.gt' => '数量需为大于0整数',
                'need_points.required' => '所需积分不能为空',
                'need_points.integer' => '所需积分需为大于0整数',
                'need_points.gt' => '所需积分需为大于0整数',
                'piecelimit.required' => '兑换次数限制不能为空',
                'piecelimit.integer' => '兑换次数限制参数错误',
                'piecelimit.gt' => '兑换次数限制参数错误',
                'valid_type.required' => '有效期类型不能为空',
                'valid_type.in' => '有效期类型参数错误',
                'gift_img.required' => '礼品图片不能为空',
            ];
        }
    }
}
